<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" media="screen" href="../../css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" media="screen" href="../../css/dataTables.bootstrap.min.css">
<link rel="stylesheet" href="../../layui/css/layui.css" media="all" />
</head>
<body>
    <div>
        <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
            <div>
                <header style="height: 100%">
                    <div align="left">
	                    <table style="width: 100%">
	                   		<tr>
	                   			<td align="right">
	                   				<button class="layui-btn layui-btn-sm" onclick="location.href='addPGoodsType.html'">
                                      <i class="layui-icon">&#xe608;</i> 添加
                                    </button>
	                   			</td>
	                   		</tr> 
	                    </table>
					</div>
                </header>
                
                <div>
                    <div class="widget-body no-padding">
                        <table id="dt-table" class="table table-striped table-bordered table-hover" style="width:100%">
                            <thead>
                                <tr>
                                </tr>                       
                                <tr>
									<th>id</th>
									<th>名称</th>
									<th>是否生鲜</th>
									<th>创建时间</th>
									<th>更新时间</th>
									<th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
</html>

<script type="text/javascript" src="../../js/libs/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="../../js/jq.js"></script>
<script type="text/javascript" src="../../js/plugin/datatables/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="../../js/plugin/datatables/dataTables.bootstrap.min.js"></script>
<script type="text/javascript" src="../../layui/layui.js"></script>
<script type="text/javascript" src="../../js/my/permission.js"></script>
<script type="text/javascript">
var pers = checkPermission();

initMenuList();
function initMenuList(){
    $.ajax({
        type : 'get',
        url : '/pGoodsTypes',
        contentType: "application/json; charset=utf-8",  
        async:false,
        success : function(data) {
            var length = data.length;
            for(var i=0; i<length; i++){
                var d = data[i];
                var tr = "<tr data-tt-id='" + d['id'] + "' data-tt-parent-id='" + d['pid'] + "'>";
                var td1 = "<td>" + d['name'] +"</td>";
                tr += td1;
                var id = "<td>" + d['id'] +"</td>";
                tr += id;
                var is_fresh = "";
                if(d['is_fresh'] != null){
                	is_fresh = d['is_fresh'];
                }
                var td2 = "<td>" + is_fresh +"</td>";
                tr += td2;
                
               
                var id = d['id'];
                var href = "updatePGoodsType.html?id=" + id;
                var edit = buttonEdit(href, "prj:goods", pers);
                var del = buttonDel(id, "prj:goods", pers);
                tr += "<td>"+edit + del+"</td>";
                tr += "</tr>"
                $("#dt-table").append(tr);
            }
        }
    });
}

layui.use('layer', function(){
    var layer = layui.layer;
});

function del(id){
	layer.confirm('确定要删除吗？', {
        btn : [ '确定', '取消' ]
    }, function() {
    	$.ajax({
            type : 'delete',
            url : '/pGoodsTypes/'+id,
            success : function(data) {
                example.ajax.reload();
                layer.msg("删除成功");
            }
        });
        
        layer.close(1);
    });
}

var option = {
        expandable : true,
        clickableNodeNames : true,
        onNodeExpand : function() {
            var d = this;
            console.log(d['id']);
            console.log(d['pid']);
        },
        onNodeCollapse : function() {
            var d = this;
            console.log(d['id'] + "Collapse");
            console.log(d['pid'] + "Collapse");
        }

    };

    $("#dt-table").treetable(option);
</script>
